package poc.scc.web.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import poc.scc.core.Uf;
import poc.scc.dao.hibernate.UfDao;

@Controller
@RequestMapping("uf")
public class UfController {
	
	@Autowired
	UfDao dao;
	
	@RequestMapping(value="new")
	public String newUf(Model model){
		Uf uf = new Uf();
		model.addAttribute("newUf", uf);
		
		model.addAttribute("messages", "Cadastre uma nova Uf");
		return "/uf/new";
	}
	
	@RequestMapping(value="/create", method=RequestMethod.POST)
	public String create( @ModelAttribute("newUf") Uf uf, Model model){
		System.out.println(uf);
		dao.create(uf);
		model.addAttribute("messages", "Uf criada com sucesso");
		return "/uf/new";
		
	}
}
